<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>lowerCamelCase</title>
</head>

<body>
    <div>打开浏览器控制台查看结果</div>
    <script>
        function lowerCamelCase(arg, hyphen) {
            let arr = arg.split(hyphen || '-');
            for (let i = 1; i < arr.length; i++) {
                arr[i] = arr[i].charAt(0).toUpperCase() + arr[i].substring(1);
            }
            return arr.join('');
        }
        function lowerCamelCaseByRegExp(arg, hyphen) {
            const reg = new RegExp((hyphen || '-') + '[a-zA-Z]', 'g');
            return arg.replace(reg, rep => rep.charAt(1).toUpperCase());
        }
        console.log(lowerCamelCase('class-last-name'), lowerCamelCaseByRegExp('class-last-name')); // classLastName
        console.log(lowerCamelCase('class_last_name', '_'), lowerCamelCaseByRegExp('class_last_name', '_'));// classLastName
    </script>
</body>

</html>